<script type="text/javascript"> 
//日志检索的函数 ，结果显示在id="tableDiv"的区域 
   function searchlog() {
    $("#tableDiv").html('<img src=/style/loading.gif></img>'); //运行后先显示loading图片，
    $.post("/cgi-bin/tenOC_Search.py", //数据post给/cgi-bin/tenOC_Search.py
  {
    SIP:$('#SIP').val(), //post参数SIP,从id为SIP的input框取值,要查询的ip
    logtime:$('#logtime').val(),//post参数logtime,从id为logtime的输入框取值,要查询的日志时间

  },
   function(data,status){
    $("#tableDiv").html(data)  //将/cgi-bin/tenOC_Search.py返回的日志信息显示在id=tableDiv的区域，为table格式
  });
   
}  
</script>
<form    role="form" action="/src/changeStat_tenOC.php" method="post" > <!--/src/changeStat_tenOC.php修改监控状态，取值从id="selected"的checkbox取-->
<script type="text/javascript">
    function search(obj) {//导航栏里的搜索框调用的搜索函数，搜索tr元素的内容，显示与搜索框的值匹配的tr，即表格的行
        $('tr').hide().filter(":contains('" +($(obj).val()) + "')").show()
    }
  </script>
<div class="row">
<div class="col-md-2"> <!--侧边功能栏，功能按钮和日志检索，宽度为2列-->
<div class="hidden-xs" style="position:fixed;"><!--小屏模式下不显示-->
<div class="btn-group-vertical  " style="width: 200px;">
	<button class="btn btn-default" type="submit" name="stat" value="yes">开启选中主机监控</button>
    <button class="btn btn-default" type="submit" name="stat" value="no">禁用选中的主机监控</button>
	 <button type="button" class="btn btn-default" onclick="$('tr').show()" value="yes">显示所有</button>
    <button type="button" class="btn btn-default" onclick="search(this)" value="yes">显示监控的主机</button>
    <button type="button" class="btn btn-default" onclick="search(this)" value="no">显示不监控的主机</button>
    <button type="button" class="btn btn-default" onclick="search(this)" value="red">显示丢包的主机</button>
    <button type="button" class="btn btn-default" onclick="window.open('http://113.215.1.161/log')">监控日志</button>
    <button type="button" class="btn btn-default" onclick="window.open('http://113.215.1.161/log/scanlog.txt')">扫描新增日志</button>
</div>
<hr>
  <div class="form-group">
    <label for="name">日志筛选：</label>
    <p>日期选择：</p>
    <select class="form-control" id="logtime">
      <?php 
      $dir="/var/www/html/log";
      $file=scandir($dir);
      array_multisort($file,SORT_DESC);
      foreach ($file as $name){
        if (strpos($name,"检测日志.txt")!==false){
          printf('<option value ="%s">%s</option>',$name,strstr( $name, '.', TRUE));
        }
      #echo $name;
      }
      ?>
    </select>
    <p>查询的ip：</p>
    <input type="text" id="SIP" class="form-control" placeholder="为空查询所有">
      <br>
    <button type="button" class="btn btn-default" onclick="searchlog()">查询日志</button>
  </div>
</div>
</div>
<div class="col-md-10 " id="tableDiv">

<?php
header("Content-type: text/html; charset=utf-8");
$con = mysql_connect("113.215.1.161","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
//code
mysql_select_db("mydb", $con);//选库
mysql_query("set names 'utf8'");
$result = mysql_query("SELECT * FROM ten_oc ORDER BY mon DESC,lossRate DESC");
echo '<table id="store" class="table-bordered table-hover table-striped" style="width:100%; text-align:center">
<tr style="text-align:center">
<th style="text-align:center">检测时间</th>
<th style="text-align:center">主机</th>
<th style="text-align:center">端口</th>
<th style="text-align:center">丢包率</th>
<th style="text-align:center">延迟</th>
<th style="text-align:center">监控状态</th>
<th style="text-align:center">选择主机</th>
</tr>';
while($row = mysql_fetch_array($result))
  {
    if ($row["mon"]=="no"){
      echo "<tr style='color:grey' class='warning'>";
    }
    elseif((float)$row['lossRate']>=1){
      echo "<tr style='color:red' class='danger'>";
    }
    else{echo "<tr  class='info'>";}
    echo "<td>" . $row['date'] . "</td>";
  
  	echo "<td>" . $row['host'] . "</td>";

    echo "<td>" . $row['port'] . "</td>";
	if((float)$row['lossRate']>=1)
	{
		printf("<td style='color:red' class='warning'>%.2f%%</td>",$row['lossRate']);
	}
	else
	{
		printf("<td>%.2f%%</td>",$row['lossRate']);
	}
  	//echo "<td>" . $row['time'] . "</td>";

  	printf("<td>%.2f 毫秒</td>",$row['time']);

  	

  	echo "<td>" . $row['mon'] . "</td>";
  	
	printf('<td style=" text-align:center">  <input id="selected" type="checkbox" name="domain[]" value="%s" >选中',$row['host']);
  echo "</td></tr>";
  }
echo "</table>";
echo "</form>";
mysql_close($con);
?> 
</div>
</div>
